<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/loginDialog.css" rel="stylesheet">
<title>Insert title here</title>
</head>
<script src="js/jquery-2.1.4.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<!-- 默认配置文件 -->
    <script type="text/javascript" charset="utf-8" src="uedit/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="uedit/ueditor.all.min.js"> </script>
    <!-- 语言文件 -->
    <script type="text/javascript" charset="utf-8" src="uedit/lang/zh-cn/zh-cn.js"></script>
    <!-- 如果需要页面渲染的话引入 -->
    <script type="text/javascript" charset="utf-8" src="uedit/ueditor.parse.min.js"></script>
<script type="text/javascript">
var ue = UE.getEditor('ueditor');
$(function(){
	var body_height = $("body").width();
	$("#login").click(function(){
		$("#LoginBox").css({display:"block"});
	});
	$("#loginbtn").click(function(){
		var account = $("#txtName").val();
		var psd = $("#txtPwd").val();
		var user = {"account":account,"psd":psd};
		$.ajax({
			data:user,
			type:"POST",
			url:"user/getuser",
			success:function(json){
				location.reload();
			}
		});
	});
	function getMsg(){
		$.ajax({
			url:"msg/getMsg",
			success:function(json){
				var data = JSON.parse(json);
				var msg = "";
				for(var i = data.length-1;i>=0;i--){
					 msg = msg+data[i].datetime+"&nbsp;&nbsp;&nbsp;"+data[i].addr+"<br>"+data[i].msg +"<br>";
				}
				$("#screen").html(msg);
			}
		});
	}
	setInterval(getMsg, 1000);
});
function submitMsg(){
	var msg = $("#msg").val();
	var msg = {"msg":ue.getContent()};
	$.ajax({
		type:"post",
		url:"msg/insertMsg",
		data:msg,
		success:function(data){
			var d = JSON.parse(data);
			ue.setContent("");
		}
	});
}
</script>
<body>
	<div class="container">
		<div id="LoginBox">
			<div class="row1">
				登录DIY账号窗口<a href="javascript:void(0)" title="关闭窗口" class="close_btn"
					id="closeBtn">×</a>
			</div>
			<div class="row2" >
				用户名: <span class="inputBox"> <input type="text" id="txtName"
					placeholder="账号/邮箱" />
				</span><a href="javascript:void(0)" title="提示" class="warning" id="warn">*</a>
			</div>
			<div class="row2">
				密&nbsp;&nbsp;&nbsp;&nbsp;码: <span class="inputBox"> <input
					type="text" id="txtPwd" placeholder="密码" />
				</span><a href="javascript:void(0)" title="提示" class="warning" id="warn2">*</a>
			</div>
			<div class="row2">
				<a href="#" id="loginbtn">登录</a>
			</div>
		</div>
		<div class="row">
			<div class="col-md-4 col-md-offset-5">
				<h1>WELCOME！</h1>
			</div>
			<div class="col-md-2 col-md-offset-1" style="padding-top: 20px">
			<c:if test="${empty sessionScope.user}">
				<button class="btn btn-default" type="button" id="login">登入</button>
				<button class="btn btn-default" type="button" id="rex">注册</button>
			</c:if>
				<c:if test="${not empty sessionScope.user}">
				<h3>欢迎<strong>${user.name}</strong>登入！</h3>
			</c:if>
			</div>
		</div>
		<div class="row" style="margin-top: 100px">
			<div class="col-md-6">
				<ul>
  					<li></li>
  					<li></li>
				</ul>
			</div>
			<div class="col-md-6">
				<div id="screen" style="overflow: auto; height: 400px;"></div>
				<div></div>
			</div>
		</div>
		<div class="row">
			<script id="ueditor" type="text/plain"></script>
		</div>
		<div class="row">
			<button class="btn btn-default" style="margin-top: 10px"
				onclick="submitMsg()">Enter</button>
		</div>
	</div>
</body>
</html>